package org.yuci.concurency.semaphore;

import java.util.concurrent.Semaphore;

public class Worker implements Runnable {
    
    private Semaphore workPermit;
    
    @Override
    public void run() {
        // Start a new job
        
        try {
            while (true) {
                // Do the job
            }
        } catch (Exception e) {
            // E.g., resign
        } finally {
            // quit the job
            workPermit.release();
        }
    }

    public Semaphore getWorkPermit() {
        return workPermit;
    }

    public void setWorkPermit(Semaphore workPermit) {
        this.workPermit = workPermit;
    }

}
